package com.itheima.service.Impl;

import com.itheima.common.pojo.OrderSetting;
import com.itheima.mapper.OrderMapper;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    /**
     * 根据日期修改可预约人数
     * @param orderSetting
     */
    @Transactional
    public void updateNumberByDate(OrderSetting orderSetting) {
        // 检查此数据是否存在
        Long count = orderMapper.findCountByOrderDate(orderSetting.getOrderDate());
        if (count > 0){
            // 如果存在，则更新
            orderMapper.editNumberByOrderDate(orderSetting);
        }else{
            // 如果不存在，则添加
            orderSetting.setReservations(0);
            orderMapper.add(orderSetting);
        }
    }

}
